
<template>
  <div class="body">
    <header class="header">
      <div class="title">
        <img src="../../assets/images/01_11.png" @click="getBack" alt class="img_zuo" />
        <div>数据地图</div>
      </div>
    </header>
    <div class="contant">
      <div id="ditu">
        <div class="search-box small-search" v-show="searchSelector||searchSelector===0">
          <div class="search-input">
            <input type="text" placeholder="请输入地址/名称/姓名/类别/单位" v-model="searchValue" @keyup.enter="searchList(null)" />
            <div class="search-img" v-show="!(searchValue||searchValue===0)">
              <img src="../../assets/images/mhcx_look.png" />
            </div>
            <div class="search-img" v-show="searchValue||searchValue===0" @click="searchValue=''">
              <img src="../../assets/images/mhcx_clear.png" />
            </div>
          </div>
        </div>
      </div>
      <div class="search-box" v-show="!(searchSelector||searchSelector===0)">
        <div class="search-input">
          <input type="text" placeholder="请输入地址/名称/姓名/类别/单位" v-model="searchValue" @keyup.enter="searchList(null)" />
          <div class="search-img" v-show="!(searchValue||searchValue===0)">
            <img src="../../assets/images/mhcx_look.png" />
          </div>
          <div class="search-img" v-show="searchValue||searchValue===0" @click="searchValue=''">
            <img src="../../assets/images/mhcx_clear.png" />
          </div>
        </div>
        <div class="search-search-btn" v-show="searchValue||searchValue===0" @click="searchList(null)">查询</div>
        <div class="search-search-btn" v-show="!(searchValue||searchValue===0)" @click="toSearch">
          <img class="searchSelector-menu" src="../../assets/images/sg.png" />
        </div>
      </div>
      <div class="search-box" v-show="searchSelector||searchSelector===0">
        <div class="searchSelector" v-html="searchSelector"></div>
        <div class="search-search-btn" @click="clearSearch">
          <img class="searchSelector-close" src="../../assets/images/false.png" />
        </div>
      </div>
    </div>
    <Tabbar></Tabbar>

    <div class="tk msg_tk" v-show="msg_tk">
      <div class="tk-bg" @click="closeMsg"></div>
      <div class="tk-box">
        <div class="tk-head">
          <div class="tk-head-title">提示</div>
          <img class="tk-head-close" src="../../assets/images/tk_x.png" @click="closeMsg">
        </div>
        <div class="tk-list">
          <div class="tk-item">
            <span>{{msg}}</span>
          </div>
        </div>
        <div class="tk-btns">
          <div class="tk-btn radius-m" @click="closeMsg">确定</div>
        </div>
      </div>
    </div>

    <div class="tk showDetail_tk" v-show="showDetail">
      <div class="tk-bg" @click="closeShowDetail"></div>
      <div class="tk-box">
        <div class="tk-list">
          <div class="tk-item">
            <div class="tk-item-name">档案类别:</div>
            <div class="tk-item-value" v-show="detailObj.fileCategory=='住改非'">住改非</div>
            <div class="tk-item-value" v-show="detailObj.fileCategory=='九小门店'">九小门店</div>
            <div class="tk-item-value" v-show="detailObj.fileCategory=='建筑物'">建筑物</div>
            <div class="tk-item-value" v-show="detailObj.fileCategory=='企业'">企业</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='住改非'">
            <div class="tk-item-name">小区名称:</div><div class="tk-item-value">{{detailObj.mc}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='建筑物'">
            <div class="tk-item-name">建筑名称:</div><div class="tk-item-value">{{detailObj.mc}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='九小门店'">
            <div class="tk-item-name">单位名称:</div><div class="tk-item-value">{{detailObj.mc}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='企业'">
            <div class="tk-item-name">企业名称:</div><div class="tk-item-value">{{detailObj.mc}}</div>
          </div>
          <div class="tk-item">
            <div class="tk-item-name">具体地址:</div><div class="tk-item-value">{{detailObj.address}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='住改非'">
            <div class="tk-item-name">用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;途:</div><div class="tk-item-value">{{detailObj.type}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='建筑物'">
            <div class="tk-item-name">产权性质:</div><div class="tk-item-value">{{detailObj.type}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='建筑物'">
            <div class="tk-item-name">层&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数:</div><div class="tk-item-value">{{getJzcs(detailObj.floorNum)}}</div>
          </div>
          <div class="tk-item" v-show="detailObj.fileCategory=='九小门店'">
            <div class="tk-item-name">类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别:</div><div class="tk-item-value">{{getTypeObj('九小门店',detailObj.type,'id').mc}}</div>
          </div>
          <div class="tk-item xq-box" @click="openXq">
            <div class="xq-btn">详情></div>
          </div>
        </div>
      </div>
    </div>


  </div>
</template>
<script>
  import { Dialog } from "vant";
  import Tabbar from "../tabbar.vue";
  import utils from "../../assets/js/utils.js"
  import terminal from "../../assets/js/terminal";
  export default {
    name: "data_map",
    data() {
      return {
        map:null,
        markers:[],
        userMarker:null,
        searchValue:'',//搜索框的内容
        searchSelector:'',
        jdsqObj:{},//用户的街道、社区和权限信息
        msg_tk:false,//控制是否显示 模糊查询没有数据的提示
        msg:'',
        showDetail:false,//控制是否显示  点击地图上的标点后的弹框
        detailObj:{},//点击地图上的标点的数据
        geolocation_timer:null,
        yc_flag:false,//延迟关闭弹框
        types:null,
        userId:null,
        terminal: false,
        timer:null,
        setCenterFlag:false
      };
    },
    components: {
      Tabbar
    },
    methods: {
        openXq(){
          if(this.yc_flag){
            return;
          }
          var xqda_params = {
            xq_id:this.detailObj.id,//详情id
            from:'/data_map'//详情返回路径
          };
          if(this.detailObj.fileCategory=='住改非'||this.detailObj.fileCategory=='建筑物'||this.detailObj.fileCategory=='九小门店'||this.detailObj.fileCategory=='企业'){
            localStorage.setItem("xqda_params",JSON.stringify(xqda_params));
          }
          if(this.detailObj.fileCategory=='住改非'){
            this.$router.push("/zgf_see");
          }else if(this.detailObj.fileCategory=='建筑物'){
            this.$router.push("/jzw_see");
          }else if(this.detailObj.fileCategory=='九小门店'){
            this.$router.push("/jxmd_see");
          }else if(this.detailObj.fileCategory=='企业'){
            this.$router.push("/qy_see");
          }
        },
        updateObj(obj){
          for(var n=0;n<this.markers.length;n++){
            if(this.markers[n].dataObj.id===obj.id){
              if(this.markers[n].dataObj.fileCategory=='住改非'){
                this.markers[n].dataObj.mc = obj.xq;
                this.markers[n].dataObj.type = obj.yt;
                this.markers[n].dataObj.address = obj.dizhi;
              }else if(this.markers[n].dataObj.fileCategory=='九小门店'){
                this.markers[n].dataObj.mc = obj.dwMc;
                this.markers[n].dataObj.type = obj.type;
                this.markers[n].dataObj.address = obj.address;
              }else if(this.markers[n].dataObj.fileCategory=='建筑物'){
                this.markers[n].dataObj.mc = obj.name;
                this.markers[n].dataObj.type = this.getTypeObj('建筑物',obj.propertyNature,'id').mc;
                this.markers[n].dataObj.address = obj.address;
                this.markers[n].dataObj.floorNum = obj.floornum;
              }else if(this.markers[n].dataObj.fileCategory=='企业'){
                this.markers[n].dataObj.mc = obj.enterpriseName;
                this.markers[n].dataObj.type = '';
                this.markers[n].dataObj.address = obj.enterpriseAddress;
              }
            }
          }
          if(this.detailObj.fileCategory=='住改非'){
            this.detailObj.mc = obj.xq;
            this.detailObj.type = obj.yt;
            this.detailObj.address = obj.dizhi;
          }else if(this.detailObj.fileCategory=='九小门店'){
            this.detailObj.mc = obj.dwMc;
            this.detailObj.type = obj.type;
            this.detailObj.address = obj.address;
          }else if(this.detailObj.fileCategory=='建筑物'){
            this.detailObj.mc = obj.name;
            this.detailObj.type = this.getTypeObj('建筑物',obj.propertyNature,'id').mc;
            this.detailObj.address = obj.address;
            this.detailObj.floorNum = obj.floornum;
          }else if(this.detailObj.fileCategory=='企业'){
            this.detailObj.mc = obj.enterpriseName;
            this.detailObj.type = '';
            this.detailObj.address = obj.enterpriseAddress;
          }
        },
        showMsg(msg){
          var _this = this;
          _this.msg = msg;
          _this.msg_tk = true;
          _this.yc_flag = true;
          _this.$forceUpdate();
          setTimeout(function(){
            _this.yc_flag = false;
            _this.$forceUpdate();
          },100);
        },
        closeMsg(){
          if(this.yc_flag){
            return;
          }
          this.msg = '';
          this.msg_tk = false;
        },
        toSearch(){
          if(this.jdsqObj.get_flag=='完成'){
            this.$router.push('/data_map_search');
          }else if(this.jdsqObj.get_flag=='正在'){
            this.$toast('正在获取街道和社区信息,请稍后重试');
          }else if(this.jdsqObj.get_flag=='失败'){
            this.$toast('没有获取到街道和社区信息');
          }
        },
        getBack () {//返回
          //this.$router.push('/index');
          this.$router.back()
        },
        jiequ(str,num,tail){//截取字符串
          tail = tail?(''+tail):'';
          if((str||str===0)&&str.length>num){
            str = str.substring(0,num)+tail;
          }
          return str;
        },
        createMap(){//创建地图
          var _this = this;
          _this.map = new AMap.Map('ditu',{
          	zoomEnable: true, //地图是否可缩放，默认值为true
          });
          // 传入经纬度，设置地图中心点
          //渝中区106.57,29.55
          //杨家坪106.512339,29.505386
          var position = new AMap.LngLat(_this.$global_msg.centerJwd.jd,_this.$global_msg.centerJwd.wd);  // 标准写法
          _this.map.setCenter(position);
          // 设置地图级别，级别为数字。
          // PC上，参数zoom可设范围：[3,18]；
          // 移动端：参数zoom可设范围：[3,19]
          _this.map.setZoom(18);

          //地图点击事件
          /*_this.map.on('click', function(ev) {
          	// 触发事件的对象
            var target = ev.target;
            // 触发事件的地理坐标，AMap.LngLat 类型
            var lnglat = ev.lnglat;
            // 触发事件的像素坐标，AMap.Pixel 类型
            var pixel = ev.pixel;
            // 触发事件类型
            var type = ev.type;

            //清楚所有标点
            // for(var n=0;n<_this.markers.length;n++){
            //   _this.map.remove(_this.markers[n]);
            // }
            //创建标点
            _this.biaodian(lnglat);
          });*/
          _this.startGeolocation();
        },
        startGeolocation(){//开始定位
          var _this = this;
          clearInterval(_this.geolocation_timer);
          _this.geolocation_timer = null;
          _this.map.plugin('AMap.Geolocation', function() {
              var geolocation = new AMap.Geolocation({
                  // 是否使用高精度定位，默认：true
                  enableHighAccuracy: true,
                  // 设置定位超时时间，默认：无穷大
                  //timeout: 10000,
                  // 定位按钮的停靠位置的偏移量，默认：Pixel(10, 20)
                  //buttonOffset: new AMap.Pixel(10, 20),
                  //  定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                  //zoomToAccuracy: false,
                  //  定位按钮的排放位置,  RB表示右下
                  //buttonPosition: 'RB'
               })

              // 监听获取位置信息成功的回调函数
              AMap.event.addListener(geolocation, 'complete', onComplete);
              // 监听获取位置信息错误的回调函数
              AMap.event.addListener(geolocation, 'error', onError);

              function usePosition(lng,lat){
                var position = {};
                if (_this.terminal !== true) {
                  position = utils.getGpsPosition(lng,lat);
                } else {
                  position = new AMap.LngLat(lng,lat);
                }
                if (_this.userMarker) {
                  _this.userMarker.setPosition(position);
                  //_this.userMarker.setPosition([106.512339,29.505386]);
                  if (_this.setCenterFlag) {
                    _this.setCenterFlag = false;
                    _this.map.setCenter(position);
                  }
                } else {
                  //创建标点
                  _this.markUser(position);
                }
              }

              function onComplete (data) {
                usePosition(data.position.lng,data.position.lat);
              }

              function onError (error) {
                  // 定位出错
                  //console.log(error)
                  if(error.message=='Geolocation permission denied.'){
                    //_this.tishiDw();
                  }
                  utils.getPosition(function(lng,lat){
                    console.log('切换使用sdk获取定位成功:'+lng+','+lat);
                    usePosition(lng,lat);
                  },function(msg){
                    console.log('获取定位错误:'+msg);
                  });
              }

              function startGetDw(){
                plus.geolocation.getCurrentPosition(function(p) {
                  geolocation.getCurrentPosition();
                  _this.geolocation_timer =  setInterval(function(){
                    // 获取当前位置信息
                    geolocation.getCurrentPosition();
                  },1000);
                }, function(e) {
                	_this.tishiDw();
                });
              }
              if(plus){
              	startGetDw();
              }else{
              	document.addEventListener('plusready',function(){
                  startGetDw();
                },false);
              }

              // 自动适配到合适视野范围
              // 无参数，默认包括所有覆盖物的情况
              _this.map.setFitView();
          })
        },
        tishiDw(){
          var _this = this;
          var isAndroid = terminal.terminals().android;
          Dialog.confirm({
            title: '提示',
            message: '请打开定位',
            confirmButtonText: "去设置", //改变确认按钮上显示的文字
            cancelButtonText: "取消" //改变取消按钮上显示的文字
          }).then(() => {
            //console.log("点击了确认按钮噢")
            if(isAndroid){//安卓系统
              var main = plus.android.runtimeMainActivity();
              var Intent = plus.android.importClass("android.content.Intent");
              var mIntent = new Intent('android.settings.LOCATION_SOURCE_SETTINGS');
              main.startActivity(mIntent);
            }else{//IOS系统
              var UIApplication = plus.ios.import("UIApplication");
              var NSURL = plus.ios.import("NSURL");
              var setting = NSURL.URLWithString("app-settings:");
              var application = UIApplication.sharedApplication();
              application.openURL(setting);
              plus.ios.deleteObject(setting);
              plus.ios.deleteObject(application);
            }
          }).catch(() => {
            //console.log("点击了取消按钮噢")
          });
          _this.stopGeolocation();
        },
        stopGeolocation(){//停止定位
          clearInterval(this.geolocation_timer);
          clearInterval(this.timer);
          this.geolocation_timer = null;
          this.timer = null;
        },
        markUser(lnglat){//用户标点
          var _this = this;
          var img_url = require('../../assets/images/yhwz.png');
          var content = '';
          content+='<div>';
          	content+='<img style="width: 0.601851rem;height: 0.518518rem;position: relative;top: -0.185185rem;" src="'+img_url+'"/>';
          content+='</div>';
          // 创建一个 Marker 实例：
          var marker = new AMap.Marker({
          	position: lnglat,// 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
          	//title: '标点',
          	content: content
          });
          // 设置点标记的动画效果，此处为弹跳效果
          //marker.setAnimation('AMAP_ANIMATION_BOUNCE');
          // 将创建的点标记添加到已有的地图实例：
          //marker.dataObj = obj;
          _this.map.add(marker);
          _this.userMarker = marker;
          if(_this.setCenterFlag){
            _this.setCenterFlag = false;
            _this.map.setCenter(lnglat);
          }
        },
        biaodian(obj,yh_flag){//标点
          var _this = this;
          var img_url = yh_flag?require('../../assets/images/yj.png'):require('../../assets/images/wyj.png');

          var content = '';
          content+='<div>';
          	content+='<img style="width: 0.555555rem;height: 0.712962rem;position: relative;top: -0.185185rem;" src="'+img_url+'"/>';
          content+='</div>';
          // 创建一个 Marker 实例：
          var lnglat = obj.map.split(',');
          var marker = new AMap.Marker({
          	position: lnglat,// 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
          	//title: '标点',
          	content: content
          });
          // 设置点标记的动画效果，此处为弹跳效果
          //marker.setAnimation('AMAP_ANIMATION_BOUNCE');
          // 将创建的点标记添加到已有的地图实例：
          marker.dataObj = obj;
          marker.on('click',function(o){
          	console.log(o)
            //_this.map.remove(o.target);
            _this.look(o.target.dataObj);
          });
          _this.map.add(marker);
          _this.markers.push(marker);
          //_this.map.setFitView();
        },
        look(obj){//点击地图上标点后执行的操作
          console.log(obj)
          var _this = this;
          _this.detailObj = obj;
          _this.showDetail = true;
          _this.yc_flag = true;
          _this.$forceUpdate();
          setTimeout(function(){
            _this.yc_flag = false;
          },100);
        },
        closeShowDetail(){
          if(this.yc_flag){
            return;
          }
          this.showDetail = false;
        },
        searchList(searchObj){//模糊查询
          var _this = this;
          //_this.showMsg('还没有接口');
          try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }
          _this.timer = setInterval(function(){
            if(_this.userMarker){
              clearInterval(_this.timer);
			  _this.timer = null;

              try{
                plus.nativeUI.closeWaiting();
              }catch(e){
                console.log(e.message);
              }
              if(searchObj){
                _this.searchByMore(searchObj);
              }else{
                if(_this.jdsqObj.get_flag=='完成'){
                  _this.searchByMc();
                }else if(_this.jdsqObj.get_flag=='正在'){
                  _this.$toast('正在获取街道和社区信息,请稍后重试');
                }else if(_this.jdsqObj.get_flag=='失败'){
                  _this.$toast('没有获取到街道和社区信息');
                }
              }
            }
          },100);
        },
        searchByMc(){
          var _this = this;
          try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }

          var position = _this.userMarker.getPosition();
          var searchSelector = _this.searchValue;

          var url = _this.$global_msg.Url.host + "/dataAtlas/selectDataAtlas";
          var params = {
            streetId:_this.jdsqObj.jd_id,//街道id
            communityId:_this.jdsqObj.sq_id,//社区id
            userId:_this.userId,
            queryName:_this.searchValue,
            longitude:position.lng,//经度
            latitude:position.lat//纬度
          };
          _this.axios.get(url,{
          	params: params
          }).then(function (data) {
            try{
              plus.nativeUI.closeWaiting();
            }catch(e){
              console.log(e.message);
            }
            console.log('findZgfinfoListByMultiConditions:',data);
            if(data&&data.data){
              if(data.data.code==0){
                var list = [];
                if(data.data.rows&&data.data.rows.jxmd&&data.data.rows.jxmd.length>0){
                  list = list.concat(data.data.rows.jxmd);
                }
                if(data.data.rows&&data.data.rows.jzw&&data.data.rows.jzw.length>0){
                  list = list.concat(data.data.rows.jzw);
                }
                if(data.data.rows&&data.data.rows.qy&&data.data.rows.qy.length>0){
                  list = list.concat(data.data.rows.qy);
                }
                if(data.data.rows&&data.data.rows.zgf&&data.data.rows.zgf.length>0){
                  list = list.concat(data.data.rows.zgf);
                }
                _this.mark_list(list,position,searchSelector);
              }else{
                _this.$toast(data.data.msg);
              }
            }else{
              _this.$toast('查询失败');
            }
          });


        },
        searchByMore(searchObj){
          var _this = this;
          try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }

          var position = _this.userMarker.getPosition();
          var obj = {
            jwd:position.lng+','+(position.lat+0.0003),
            show_type:'zgf'
          };
          var searchSelector = '';
          var jdid = null;
          var sqid = null;
          var lbid_b = null;
          var lbid_s = null;
          var content = null;
          var yhid_b = null;
          var yhid_s = null;
          if(searchObj.jdid===-1){
            searchObj.jdid = null;
          }
          if(searchObj.sqid===-1){
            searchObj.sqid = null;
          }
          if(searchObj.jdid||searchObj.jdid===0){
            searchSelector+=searchObj.jdmc+'-';
            jdid = searchObj.jdid;
          }
          if(searchObj.sqid||searchObj.sqid===0){
            searchSelector+=searchObj.sqmc+'-';
            sqid = searchObj.sqid;
          }
          if(searchObj.lbid_b||searchObj.lbid_b===0){
            searchSelector+=searchObj.lbmc_b+'-';
            lbid_b = searchObj.lbid_b;
          }
          if(searchObj.lbid_s||searchObj.lbid_s===0){
            searchSelector+=searchObj.lbmc_s+'-';
            lbid_s = searchObj.lbid_s;
          }
          if(searchObj.mc||searchObj.mc===0){
            searchSelector+=searchObj.mc+'-';
            content = searchObj.mc;
          }
          if(searchObj.yhid_b||searchObj.yhid_b===0){
            if(searchObj.yhid_b!==2){
              searchSelector+=searchObj.yhmc_b+'隐患-';
            }
            yhid_b = searchObj.yhid_b;
          }else{
            yhid_b = 2;
          }
          if(searchObj.yhid_s||searchObj.yhid_s===0){
            searchSelector+=searchObj.yhmc_s+'-';
            yhid_s = searchObj.yhid_s;
          }
          if(searchSelector){
            searchSelector=searchSelector.substring(0,searchSelector.length-1);
          }else{
            searchSelector = '不限';
          }

          var url = _this.$global_msg.Url.host + "/dataAtlas/accurateQuery";
          var params = {
            streetId:jdid,//街道id
            communityId:sqid,//社区id
            type:lbid_b,//大类
            typeId:lbid_s,//小类
            content:content,//查询内容
            dangerId:yhid_s,//隐患id
            dangerType:yhid_b,//隐患类型 0无1有2不限
            longitude:position.lng,//经度
            latitude:position.lat//纬度
          };
          _this.axios.get(url,{
          	params: params
          }).then(function (data) {
            try{
              plus.nativeUI.closeWaiting();
            }catch(e){
              console.log(e.message);
            }
            console.log('findZgfinfoListByMultiConditions:',data);
            if(data&&data.data){
              if(data.data.code==200){
                var list = data.data.rows;
                _this.mark_list(list,position,searchSelector);
              }else{
                _this.$toast(data.data.msg);
              }
            }else{
              _this.$toast('查询失败');
            }
          });
        },
        /**
         * @param {Object} list 数据
         * @param {Object} position 用户位置
         * @param {Object} searchSelector 查询条件文本
         */
        mark_list(list,position,searchSelector){
          var _this = this;
          try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }
          if(_this.map){
            _this.map.remove(_this.markers);
          }
          _this.markers = [];
          var _list = [];
          if(list&&list.length>0){
            for(var n=0;n<list.length;n++){
              var mapstr = list[n].map?list[n].map.trim():'';
              if(mapstr&&mapstr.indexOf('null')<0&&mapstr.indexOf('undefined')<0){
                var yh = list[n].isdanger>0?true:false;
                var p2 = mapstr.split(',');
                // 返回 p1 到 p2 间的地面距离，单位：米
                var dis = AMap.GeometryUtil.distance(position, p2);
                list[n].dis = dis;
                list[n].yh_flag = yh;
                _list.push(list[n]);
                //console.log('距离：',dis);
                //console.log('是否距离：',dis<=200);
                //_this.biaodian(list[n],yh);
              }
            }
          }
          //排序  从小到大
          function compare(val1,val2){
              return val1.dis-val2.dis;
          };
          _list.sort(compare);
          //最多只显示200个
          for(var n=0;n<_list.length;n++){
            if(_this.markers.length<200){
              _this.biaodian(_list[n],_list[n].yh_flag);
            }
          }
          if(_list.length>0){
            // 自动适配到合适视野范围
            // 无参数，默认包括所有覆盖物的情况
            _this.map.setFitView();
            if(_list.length==1){
              _this.setCenterByPosition(_this.markers[0].getPosition());
            }
          }
          if(_this.markers.length>0){
            _this.searchSelector = searchSelector?searchSelector:'&nbsp;';
            _this.searchValue = '';
          }else{
            _this.showMsg('查询无数据！');
          }
          try{
            plus.nativeUI.closeWaiting();
          }catch(e){
            console.log(e.message);
          }
        },
        clearSearch(){
          this.searchSelector = '';
          this.searchValue = '';
          /*if(this.map){
            this.map.remove(this.markers);
          }
          this.markers = [];*/
        },
        setCenterByPosition(lnglat){
          this.map.setCenter(lnglat);
        },
        getJzcs(cs){
          var csStr = '';
          if(cs){
          	if(cs>=10){
          		csStr = '高层建筑';
          	}else{
          		csStr = '一般建筑';
          	}
          }
          return csStr;
        },
        getJdsq(){//获取用户的街道、社区和权限信息
          var _this = this;
          try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }
          _this.jdsqObj = {
            get_flag:'正在'
          };
          _this.axios.get(_this.$global_msg.Url.host + "/nineStore/selectStreetAndBumen",{
          	params: {
              userId:_this.userId
            }
          }).then(function (data) {
            try{
              plus.nativeUI.closeWaiting();
            }catch(e){
              console.log(e.message);
            }
            console.log('selectStreetAndCommunity:',data);
            if(data&&data.data){
              _this.jdsqObj = {
                sq_id:'',//社区id
                sq_mc:'',//社区名称
                jd_id:'',//街道id
                jd_mc:'',//街道名称
                lev:data.data.rows.lev
              };
              var jd_list = [];
              var sq_list = [];
              if(data.data.rows.lev==='0'){
                //最高权限，有多个街道信息
                //data.data.rows.jd[0]
                jd_list = data.data.rows.jd;
                _this.jdsqObj.jd_select_flag = '是';
                _this.jdsqObj.sq_select_flag = '是';
              }else if(data.data.rows.lev==='1'){
                //街道
                if(data.data.rows.jd){
                  _this.jdsqObj.jd_id = data.data.rows.jd.id;
                  _this.jdsqObj.jd_mc = data.data.rows.jd.mc;
                }
                jd_list = [data.data.rows.jd];
                _this.jdsqObj.jd_select_flag = '否';
                _this.jdsqObj.sq_select_flag = '是';
              }else if(data.data.rows.lev==='2'){
                //社区
                if(data.data.rows.jd){
                  _this.jdsqObj.jd_id = data.data.rows.jd.id;
                  _this.jdsqObj.jd_mc = data.data.rows.jd.mc;
                }
                if(data.data.rows.sq){
                  _this.jdsqObj.sq_id = data.data.rows.sq.id;
                  _this.jdsqObj.sq_mc = data.data.rows.sq.mc;
                }
                jd_list = [data.data.rows.jd];
                sq_list = [data.data.rows.sq];
                _this.jdsqObj.jd_select_flag = '否';
                _this.jdsqObj.sq_select_flag = '否';
              }
              _this.jdsqObj.get_flag = '完成';
              localStorage.setItem("jd_list",JSON.stringify(jd_list));
              localStorage.setItem("sq_list",JSON.stringify(sq_list));
              localStorage.setItem("jdsqObj",JSON.stringify(_this.jdsqObj));
            }else{
              _this.$toast('查询失败');
              _this.jdsqObj.get_flag = '失败';
            }
          });
        },
        getTypes(){//获取类别
          var _this = this;
          _this.types = {};
          _this.types['建筑物'] = [
            {mc:'住宅',id:1,img:1},
            {mc:'商用',id:2,img:2},
            {mc:'商住混合',id:3,img:3},
            {mc:'其他',id:4,img:4}
          ]
          _this.types['企业'] = [
            {mc:'重点检查',id:1,img:1},
            {mc:'一般检查',id:2,img:2},
            {mc:'随机抽查',id:3,img:3}
          ]
          _this.types['九小门店'] = [
            {mc:'小商场',id:1,img:1},
            {mc:'小医院',id:2,img:2},
            {mc:'小餐饮场所',id:3,img:3},
            {mc:'小旅馆',id:4,img:4},
            {mc:'小歌舞厅娱乐场所',id:5,img:5},
            {mc:'小网吧',id:6,img:6},
            {mc:'小美容洗浴场所',id:7,img:7},
            {mc:'小生产加工企业',id:8,img:8},
            {mc:'废品回收',id:9,img:9},
            {mc:'其他',id:10,img:10}
          ];
          try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }
          //查询住改非用途
          var url = _this.$global_msg.Url.host + "/queryFile/selectYt";
          var params = {};
          _this.axios.get(url,{
          	params: params
          }).then(function (data) {
            console.log('查询弹框列表:',data);
            if(data&&data.data){
              if(data.data.code===0){
                for(var n=0;n<data.data.rows.length;n++){
                  var id = data.data.rows[n].id;
                  var img = '';
                  if(id===1){
                    img = 1;
                  }else if(id===2){
                    img = 2;
                  }else if(id===3){
                    img = 3;
                  }else if(id===4){
                    img = 4;
                  }else if(id===6){
                    img = 5;
                  }else if(id===7){
                    img = 6;
                  }else if(id===8){
                    img = 7;
                  }
                  data.data.rows[n].img = img;
                }
                _this.types['住改非'] = data.data.rows;
                _this.$forceUpdate();
              }else{
                _this.$toast(data.data.msg);
              }
            }else{
              _this.$toast('查询失败');
            }
            try{
              plus.nativeUI.closeWaiting();
            }catch(e){
              console.log(e.message);
            }
          });
        },
        /**
         * 根据id或名称获取类别信息(对象)，没有获取到就返回空对象
         * @param {Object} b_t 大类，如果为空返回空对象
         * @param {Object} s_t 小类，如果为空返回空对象
         * @param {Object} type 是根据id或mc获取，如果为空返回空对象
         */
        getTypeObj(b_t,s_t,type){
          var _this = this;
          if((b_t||b_t===0)&&(s_t||s_t===0)){
            for(var n=0;n<_this.types[b_t].length;n++){
              if(type=='id'){
                if(_this.types[b_t][n].id===s_t){
                  return _this.types[b_t][n];
                }
              }else if(type=='mc'){
                if(_this.types[b_t][n].mc===s_t){
                  return _this.types[b_t][n];
                }
              }
            }
          }
          return {};
        },
        init(){//初始化
          var _this = this;
          _this.userId = localStorage.getItem("userId"); //用户id
          console.log(terminal.terminals());
          _this.terminal = terminal.terminals().android;
          //_this.terminal = false;
          if(_this.map){
            if(_this.userMarker){
              _this.map.remove(_this.userMarker);
            }
            _this.userMarker = null;
            _this.startGeolocation();
            _this.map.remove(_this.markers);
            // 自动适配到合适视野范围
            // 无参数，默认包括所有覆盖物的情况
            _this.map.setFitView();
          }else{
            _this.userMarker = null;
            var AMap_timer = setInterval(function(){
              if(AMap){
                clearInterval(AMap_timer);
                _this.createMap();
              }
            },100);
          }
          if(!_this.types){
            _this.getTypes();
          }
          _this.setCenterFlag = true;
          _this.getJdsq();
          _this.markers = [];
          _this.searchValue = '';
          _this.searchSelector = '';
          _this.jdsqObj = {};
          _this.msg_tk = false;
          _this.msg = '';
          _this.showDetail = false;
          _this.detailObj = {};
          _this.yc_flag = false;

        }
    },
    //进入该页面时
    beforeRouteEnter (to, from, next) {
        next(vm => {
          var list_update = localStorage.getItem("list_update")?JSON.parse(localStorage.getItem("list_update")):null;
          if(list_update){
            vm.updateObj(list_update);
          }else{
            var data_map_searchObj = localStorage.getItem("data_map_searchObj")?JSON.parse(localStorage.getItem("data_map_searchObj")):null;
            if(data_map_searchObj){
              vm.searchList(data_map_searchObj);
            }else{
              vm.init();
            }
          }
          localStorage.removeItem("list_update");
          localStorage.removeItem("data_map_searchObj");
          localStorage.removeItem("xqda_params");
        })
    },
    //离开该页面时
    beforeRouteLeave(to, from, next) {
        this.stopGeolocation();
        next()
    },
    mounted() {
      var _this = this;
      //this.init();

      //物理返回
      // window.addEventListener("popstate", function(){
      //   _this.getBack();
      // }, false);
    },
    created() {

    }
  };
</script>
<style scoped>
  .contant {
    border: 1px solid white;
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 1.662963rem;
  }

  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    width: 100%;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }

  .body{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
  }

  #ditu{
    width: 100%;
    flex: 1;
  }

  /*搜索框*/
  .search-box{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f7f7f7;
  }
  .search-box .search-input{
    flex: 1;
    height: 1.111111rem;
    border-radius: 0.925925rem;
    overflow: hidden;
    margin-top: 0.185185rem;
    margin-bottom: 0.185185rem;
    margin-left: 0.37037rem;
    margin-right: 0;
    display: flex;
    position: relative;
    background-color: #FFFFFF;
  }
  .search-box .search-input input{
    height: 100%;
    flex: 1;
    background-color: #FFFFFF;
    margin-left: 0.37037rem;
  }
  .search-box .search-img{
    width: 0.851851rem;
    height: 100%;
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
  }
  .search-box .search-img img{
    width: 0.481481rem;
    height: 0.481481rem;
  }
  .search-box .search-search-btn{
    width: 1.2rem;
    height: 1.111111rem;
    margin-top: 0.185185rem;
    margin-bottom: 0.185185rem;
    color: #2b6cfe;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .searchSelector-menu{
    width: 0.518518rem;
    height: 0.518518rem;
  }
  .searchSelector-close{
    width: 0.425925rem;
    height: 0.425925rem;
  }
  .search-box .searchSelector{
    flex: 1;
    margin-left: 0.925925rem;
  }
  .small-search{
    position: absolute;
    bottom: 0.37037rem;
    left: 0.185185rem;
    z-index: 99;
    width: 7rem !important;
    background: none !important;
  }
  .small-search .search-input{
    margin: 0 !important;
  }

  /* 弹框 */
  .tk{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 130;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.388888rem;
  }
  .tk .tk-bg{
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 131;
    background-color: rgba(0,0,0,0.4);
  }
  .tk .tk-box{
    width: 8rem;
    background-color: #FFFFFF;
    z-index: 132;
    display: flex;
    flex-direction: column;
    border-radius: 0.222222rem;
  }

  .tk .tk-head{
    width: auto;
    height: 1.4351851851851851rem;
    border-bottom: 1px #ddd solid;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-left: 0.37037rem;
    margin-right: 0.37037rem;
  }
  .tk .tk-head .tk-head-title{
    flex: 1;
    height: 1.4351851851851851rem;
    display: flex;
    align-items: center;
  }
  .tk .tk-head .tk-head-close{
    width: 0.37037rem;
    height: 0.37037rem;
  }


  .tk .tk-list{
    flex: 1;
    width: 100%;
    overflow-y: scroll;
  }
  .tk .tk-item{
    width: auto;
    height: 1.3888888888888888rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-left: 0.37037rem;
    margin-right: 0.37037rem;
    border-bottom: 1px solid #DDDDDD;
  }
  .tk .tk-item .tk-item-name{
    display: flex;
    width: 1.8rem;
  }
  .tk .tk-item .tk-item-value{
    margin-left: 0.185185rem;
    height: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  .tk .tk-item .tk-item-value input{
    width: 5.555555rem;
    height: 100%;
  }
  .tk .tk-list .tk-item-checked{
    color: #2a6cfe;
  }
  .tk .tk-list .tk-item-select{
    height: 100%;
    display: flex;
    align-items: center;
  }
  .tk .tk-list .tk-item-select img{
    width: 0.444444rem;
    height: 0.444444rem;
  }

  .tk .tk-block{
    margin-left: 0.37037rem;
    margin-right: 0.37037rem;
    width: auto;
    display: flex;
    flex-wrap: wrap;
    border-bottom: 1px solid #DDDDDD;
    padding-left: 0.74074rem;
  }
  .tk .tk-block-value{
    width: 50%;
    height: 1.3888888888888888rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-top: 1px solid #DDDDDD;
  }
  .tk .tk-block-value:nth-child(1),.tk .tk-block-value:nth-child(2){
    border-top: 0 !important;
  }

  .tk .tk-btns{
    width: 100%;
    height: auto;
    display: flex;
    align-items: center;
    margin-top: 0.37037rem;
  }
  .tk .tk-btns:last-child{
    margin-bottom: 0.37037rem;
  }
  .tk .tk-btns .tk-btn{
    margin-left: 1rem;
    margin-right: 1rem;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 1.074074rem;
    background: #309dfa;
    color: #fff;
    font-size: 0.444444rem;
    border-radius: 0.148148rem;
  }
  .tk .xz-tk{
    height: 5rem !important;
  }


  .msg_tk .tk-item{
    border-bottom: none!important;
    justify-content: center !important;
  }
  .msg_tk .tk-item:nth-child(1){
    margin-top: 0.37037rem;
  }

  .showDetail_tk .tk-item{
    border-bottom: none!important;
    height: auto!important;
    margin-bottom: 0.333333rem;
  }
  .showDetail_tk .tk-item:nth-child(1){
    margin-top: 0.37037rem;
  }
  .showDetail_tk .tk-box{
    width: 7rem !important;
  }
  .showDetail_tk .tk-item-value{
    justify-content: flex-start!important;
  }

  .xq-box{
    justify-content: flex-end !important;
  }
  .xq-btn{
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2e45ca;
  }

</style>
